#ifndef ONLINE_H
#define ONLINE_H

	private static String      net_url = "http://www.caravanarock.com.ar/";
	private static HTTP        net_http = new HTTP();
	
	public interface NetError
	{
		public static final byte ERROR_CONNECTION               = -2;
		public static final byte ERROR_PENDING                  = -1;
	}
	private static long        net_callstarttime;
	private static int         net_lastErrorCode;

	public static int net_getLastError()
	{
		if (net_http.isInProgress())
		{
			return NetError.ERROR_PENDING;
		}

		if (net_http.m_bError)
		{
			return NetError.ERROR_CONNECTION;
		}

		return net_lastErrorCode;
	}

	public static boolean net_isErrorOccurred()
	{
		return net_http.isErrorOccurred();
	}

	public static void net_cancel()
	{
		if (HTTPConfig.ENABLE_TIMEOUT)
		{
			net_callstarttime = 0;
		}
		net_http.cancel();
	}

	public static void net_cleanup()
	{
		if (HTTPConfig.ENABLE_TIMEOUT)
		{
			net_callstarttime = 0;
		}
		net_http.cleanup();
	}

	public static void net_sendRequest(String page, String request)
	{
		net_http.sendByGet(net_url + page, request);
		System.out.println("URL = " + net_url + page + request);
	}

	public static byte[] net_handleResponse()
	{
		if (net_http.isInProgress())
		{
			if (HTTPConfig.ENABLE_TIMEOUT)
			{
				if ((System.currentTimeMillis() - net_callstarttime) > HTTPConfig.CONN_TIMEOUT)
				{
					net_cancel();
					net_lastErrorCode = NetError.ERROR_CONNECTION;
					return null;
				}
			}
			return null;
		}

		if (net_http.isErrorOccurred())
		{
			return null;
		}
		
		if (net_http.m_responseByteArray != null)
		{
			return net_http.m_responseByteArray;
		}

		return null;
	}

#endif // ONLINE_H